﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Platform.LanguageProcessing.Expressions;

namespace Platform.LanguageProcessing
{

	/// <summary>
	/// Representa uma gramática e suas regras
	/// </summary>
	public abstract class Grammar
	{

		protected Grammar( CultureInfo culture )
		{
			this.Culture = culture;
			this.Words = new WordDictionary<IWordParser>();
		}

		public CultureInfo Culture
		{ get; private set; }

		public WordDictionary<IWordParser> Words
		{ get; private set; }

		public GrammarExpression Parse( string text )
		{
			return this.CreateParser().Parse( text );
		}

		public abstract Parser CreateParser();


		protected void AddWordParser( string word, IWordParser parser )
		{
			this.Words.Add( word, parser );
		}

		protected void AddWordParser(string[] words, IWordParser parser )
		{
			if ( words != null )
			{
				for ( int index = 0; index < words.Length; index++ )
				{
					this.Words.Add( words[ index ], parser );
				}
			}
		}
	}
}
